
package com.sausageking.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sausageking.server.common.ServerUtil;

public class ShortUrlRedirectServlet extends HttpServlet {

  private static final long serialVersionUID = -146042423369390580L;

  private static final Logger log = Logger
      .getLogger(ShortUrlRedirectServlet.class.getName());

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    log.info(req.toString());
    String redirectUrl = getRedirectUrl(req);
    log.info(redirectUrl);

    PrintWriter out = resp .getWriter();
    resp.addHeader("REFRESH","0;url=" + redirectUrl);
    out.println("");
  }

  private String getRedirectUrl(HttpServletRequest req) {
    return new ServerUtil().getFullMerchantUrl(req.getPathInfo().substring(1));
  }
}
